package lianxi.impl;


import lianxi.Person;

import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

//多例
public class MarkPersonFactory {
    static Properties properties = new Properties();
    static {
        try {
            properties.load(MarkPersonFactory.class.getClassLoader().getResourceAsStream("person02.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public Person doPerson(String beanName) throws Exception {
        Map map = new HashMap();
        Enumeration<?> enumeration = properties.propertyNames();
        while (enumeration.hasMoreElements()) {
            String key = enumeration.nextElement() + "";
            String value = properties.getProperty(key);
            Person p = (Person)Class.forName(value).newInstance();
            map.put(key,p);
        }
        return (Person) map.get(beanName);
    }
}
